import cv2
import numpy as np

def is_same_photo(image_1,image_2,threshold=10):
    result = cv2.subtract(image_1,image_2)
    non_zero_count = cv2.countNonZero(result) #计算非0像素的数量
    return non_zero_count <= threshold #与阈值相比较

file1 = "D:/code/python/Template/0.png"
file2 = "D:/code/python/Template/1.png"
image1 = cv2.imread(file1)#打开图片0
image2 = cv2.imread(file1) # 打开图片1
gray1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
is_true = is_same_photo(gray1,gray2)
if is_true:
    print('图片相同哦~')
else:
    print('图片不同呢~')
#进行图片匹配

cv2.waitKey()